import axios from "axios";
import {error} from './api/msg.js';

const service = axios.create({
    baseURL:'http://localhost:9999',
    timeout:10000,
    timeoutErrorMessage:'系统超时!请稍后再试',
    withCredentials:true//开启axios携带cookie
})

// Add a request interceptor
service.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
service.interceptors.response.use(function (response) {
    // Do something with response data

    if (response.data.code===401){
        error(response.data.msg);
        return Promise.reject(response.data.msg);
    }else{
        return response.data;
    }

}, function (error) {
    // Do something with response error
    return Promise.reject(error);
});



export default service;